package net.atomarrow.render;

import java.io.InputStream;

public class RenderFactory {

    public Render createJspRender(String path,boolean redirectMode){
        if(!path.contains(".jsp")){
            path=path+".jsp";
        }
        return new JspRender().setAttr(JspRender.REDIRECT_PATH, path).setAttr(JspRender.REDIRECT_TYPE, redirectMode?JspRender.REDIRECT_TYPE_REDIRECT:JspRender.REDIRECT_TYPE_FORWARD);
    }

    public Render createJsonRender(String data) {
    	return new JsonRender().setAttr(JsonRender.JSON_STRING, data);
    }
    public Render createHtmlRender(String htmlText) {
    	return new HtmlRender().setAttr(HtmlRender.HTML_STRING, htmlText);
    }
    public Render createXmlRender(String xmlText) {
        return new XmlRender().setAttr(XmlRender.XML_STRING, xmlText);
    }

    public Render createActionRender(String action,boolean redirectMode) {
        return new ActionRender().setAttr(ActionRender.ACTION, action).setAttr(ActionRender.REDIRECT_TYPE, redirectMode?ActionRender.REDIRECT_TYPE_REDIRECT:ActionRender.REDIRECT_TYPE_CHAIN);
    }
    
    public Render createFileRender(String fileName, InputStream is) {
        return new FileRender().setAttr(FileRender.FILE_NAME, fileName).setAttr(FileRender.FILE_DATA_INPUTSTREAM, is);
    }
    
    public Render createImgRender(InputStream is) {
        return new ImgRender().setAttr(ImgRender.IMG_INPUTSTREAM, is);
    }

    public Render createImgRender(InputStream is,Integer width,Integer height) {
        return new ImgRender().setAttr(ImgRender.IMG_INPUTSTREAM, is).setAttr(ImgRender.IMG_WIDTH, width).setAttr(ImgRender.IMG_HEIGHT, height);
    }
    
    public Render createFreemarkerRender(String templateName) {
        return new FreemarkerRender().setAttr(FreemarkerRender.TEMPLATE_NAME, templateName);
    }

	public Render createRedirectRender(String url) {
		return new RedirectRender().setAttr(RedirectRender.URL, url);
	}

	public Render createTextRender(String text) {
		return new TextRender().setAttr(TextRender.TEXT_STRING, text);
	}
    
	public Render createErrorRender(String text) {
		return new ErrorRender().setAttr(ErrorRender.ERROR_STRING, text);
	}
}
